package com.tang.util;


import java.text.DecimalFormat;

/**
 * CreateTime: 2016-05-03下午3:51
 * Author: wjkjinke00@126.com
 * Description:
 */
public class MoneyUtil {
    /**
     * 精确为两位小数
     *
     * @param money
     * @return
     */
    public static <T> String formatMoney(T money) {
        String format = null;
        try {
            Double aDouble = Double.valueOf(String.valueOf(money));
            format = new DecimalFormat("0.0").format(aDouble);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return "0.0";
        }
        return format;
    }


    public static <T> String formatIntger(T money) {
        String format = null;
        try {
            Double aDouble = Double.valueOf(String.valueOf(money));
            format = new DecimalFormat("0").format(aDouble);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return "0";
        }
        return format;
    }

    public static <T> String formatIntger1(T money) {
        if (money != null) {
            String format = null;
            try {
                Double aDouble = Double.valueOf(String.valueOf(money));
                format = new DecimalFormat("0.0").format(aDouble);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                return "0.0";
            }
            return format;
        } else {
            return "null";
        }
    }

    public static <T> String formatIntger2(T money) {
        if (money != null) {
            String format = null;
            try {
                Double aDouble = Double.valueOf(String.valueOf(money));
                format = new DecimalFormat("0.00").format(aDouble);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                return "0.00";
            }
            return format;
        } else {
            return "null";
        }

    }

    public static <T> String formatIntger3(T money) {
        if (money != null) {
            String format = null;
            try {
                Double aDouble = Double.valueOf(String.valueOf(money));
                format = new DecimalFormat("0.000").format(aDouble);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                return "0.000";
            }
            return format;
        } else {
            return "null";
        }
    }

    /**
     * 奖金额格式化为 1,111.11
     *
     * @param money
     * @return
     */
    public static <T> String formatMoney2(T money) {
        String format = null;
        try {
            Double aDouble = Double.valueOf(String.valueOf(money));
            format = new DecimalFormat("#,##0.00").format(aDouble);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return "0.00";
        }
        return format;
    }
}
